#!/bin/bash

git pull
portParam=11002
envParam=$1
if [[ ! -n "$envParam" ]]; then
	envParam="adminDev"
elif [[ "$envParam" == "adminDev" ]]; then
    portParam=11002
elif [[ "$envParam" == "adminProd" ]]; then
    portParam=9992
fi

source go-env.sh
go install admin

echo "stop admin"

pid=`sudo netstat -nplt | grep admin | grep ${portParam} | awk '{print $7}' | awk -F / '{print $1}'`
echo "old pid: ${pid}"
if [[ ${pid} ]]
then
	echo "kill pid ${pid}"
	kill -9 ${pid}
fi


echo "starting admin in env:${envParam}, port:${portParam}"

nohup ./bin/admin ${envParam} >./logs/admin.log 2>&1 &
